package com.ashye.bindingrecyclerviewdemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    private RecyclerView recyclerView;
    private FooterBindingRecyclerAdapter<String> adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initRecyclerView();
        initFab();
    }

    private void initRecyclerView() {
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
        recyclerView.setItemAnimator(new DefaultItemAnimator());

        adapter = new FooterBindingRecyclerAdapter<String>(R.layout.binding_recycler_item, com.ashye.bindingrecyclerviewdemo.BR.itemData) {
            @Override
            public void onItemClicked(View view, int position, String item) {
                Log.e("sss", "sssssssssss: "+position);
            }
        };

        recyclerView.setAdapter(adapter);
    }

    private void initFab() {
        findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                adapter.addData("sssssffffffff ="+adapter.getItemCount());

                recyclerView.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        adapter.loading(true);
                    }
                }, 3000);

                recyclerView.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        adapter.loading(false);
                    }
                }, 6000);
                recyclerView.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        adapter.loadAll();
                    }
                }, 9000);

                recyclerView.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        adapter.loading(false);
                    }
                }, 12000);
            }
        });
    }
}
